const {Sequelize, DataTypes} = require("sequelize");
const start = require("./utils/connect");

(async()=>{
  const sequelize = await start();
  const User = sequelize.define("User",{
    firstName:{
      type:DataTypes.STRING,
      allowNull:false,
      get(){
        const rawValue = this.getDataValue("firstName");
        return rawValue ? rawValue.toUpperCase() : null;
      }
    },
    lastName:{
      type:DataTypes.STRING
    }
  },{
    freezeTableName:true, // 强制使用定义表名
  });


  await User.sync({
    // force:true,
    // alter:true
  });

  console.log("模型同步成功");

  // 方法一
  // const jane = User.build({firstName:"Jane"});
  // await jane.save();
  // console.log("保存成功")

  // 方法二
  // const joker = await User.create({firstName:"Joker",lastName:"Wu"});
  // console.log(joker.toJSON());

  // const users = await User.findByPk(1);
  // console.log(users.toJSON());

  

})()